export const getMessage = {
  data () {
    return {
      isRuning: false,
      time: 60
    }
  },
  methods: {
    sedMsg (type) {
      this.isRuning = true
      this.$ajax.post('/api/config/sms/sendSms', {
        telephone: this.userPhone,
        type: this.$route.name === 'forget' ? 2 : 1
      }).then((data) => {
        if (data.data.code === '200') {
          if (type === 'mobile') { // 手机端
            this.$tips.show({
              message: '短信发送成功'
            })
          } else {
            this.$message({
              message: '短信发送成功',
              type: 'success'
            })
          }
          this.runTime()
        } else {
          this.isRuning = false
          if (type === 'mobile') { // 手机端
            this.$tips.show({
              message: data.data.message
            })
          } else {
            this.$message({
              message: data.data.message,
              type: 'warning'
            })
          }
        }
      }).catch((err) => {
        this.isRuning = false
        console.error(err)
      })
    },
    runTime () {
      this.time = 60
      let times = setInterval(() => {
        this.time--
        if (this.time <= 0) {
          clearInterval(times)
          this.isRuning = false
        }
      }, 1000)
    }
  }
}
